<!--
 * @Author: Zcl84765
 * @Date: 2022-10-19 13:44:37
 * @LastEditors: Zcl84765
 * @LastEditTime: 2023-01-19 10:18:53
-->
<template>
  <div>
    <el-button type="primary" @click="dialogVisible = true">选择时间</el-button>
    <el-dialog
      title="选择时间"
      v-dialogDrag
      :visible.sync="dialogVisible"
      :before-close="handleClose"
    >
      <div
        v-for="(item, index) in dataList"
        :key="index"
        :class="current == index ? 'select' : 'c1'"
        @click="handleClick(index)"
      >
        <div class="data_main">
          <div>{{ item.time }}</div>
          <div>{{ index }}</div>
        </div>
      </div>

      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="submitTime()">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      dataList: [
        { time: '2019' },
        { time: '2020' },
        { time: '2021' },
        { time: '2022' },
      ],
      current: 0,
      dialogVisible: false,
    }
  },
  methods: {
    handleClick(idx) {
      this.current = idx
    },
    handleClose() {
      this.dialogVisible = false
    },
    submitTime() {
      console.log(this.dataList[this.current].time)
    },
  },
}
</script>

<style scoped lang="less">
.c1 {
  height: 80px;
  width: 300px;
  text-align: center;
  margin: 0 auto;
  border-radius: 7px;
  border: 1px solid #999;
  position: relative;
  margin-top: 10px;
  .data_main {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
  }
}
.select {
  position: relative;
  height: 80px;
  width: 300px;
  margin: 0 auto;
  text-align: center;
  color: #1990ff;
  background-color: #fff;
  box-shadow: 0px 2px 7px 0px rgba(85, 110, 97, 0.35);
  border-radius: 7px;
  border: 1px solid #1990ff;
  margin-top: 10px;
  overflow: hidden;
  .data_main {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
  }
}
.select:before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  border: 17px solid #1990ff;
  border-bottom-right-radius: 5px;
  // border-top-color: transparent;
  // border-left-color: transparent;
}
.select:after {
  content: '';
  width: 5px;
  height: 12px;
  position: absolute;
  left: 10px;
  top: 6px;
  border: 2px solid #fff;
  border-top-color: transparent;
  border-left-color: transparent;
  transform: rotate(45deg);
}
</style>
